// 倒计时组件
import { onUnmounted, computed, ref } from 'vue'
import dayjs from 'dayjs'
export const useCountDown = () => {
  const time = ref(0)
  const formatTime = computed(() => {
    return dayjs.unix(time.value).format('mm分ss秒')
  })
  let timer = null
  const start = (currentTime) => {
    time.value = currentTime
    timer = setTimeout(() => {
      time.value--
    }, 1000)
  }
  onUnmounted(() => {
    clearTimeout(timer)
  })
  return {
    formatTime,
    start
  }
}
